package com.egao.api.controller.orderB;


import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.entity.BillFee;
import com.egao.orderB.entity.BillFeeWriteOffItem;
import com.egao.orderB.service.BillFeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 * https://francjc.com:4332/swagger-ui.html
 */
@RequestMapping("/api/billFee")
@RestController
@Api(value = "订单运费管理",tags = {"订单运费管理"})
public class ApiBillFeeController extends BaseController {

    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private BillFeeService billFeeService;

    /**
     * 订单运费列表
     */
    @PreAuthorize("hasAuthority('orderB:billFee:list')")
    @PostMapping("/list")
    @ApiOperation(value = "订单运费列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "billId:订单id 必填\n" +
            "page:第几页 必填\n" +
            "type:省\n" +
            "feeName:市\n" +
            "feeState:费用状态:未确认,已确认\n" +
            " \n" +
            "返回的内容\n" +
            "id:id\n" +
            "organizationId:组织id\n" +
            "billId:订单id\n" +
            "type:类型\n" +
            "feeName:费用名称\n" +
            "standard:标准\n" +
            "feeState:费用状态:未确认,已确认\n" +
            "feePerson:确认人\n" +
            "feeTime:确认时间\n" +
            "price:金额\n" +
            "fobject:费用对象 货代,司机,码头 \n" +
            "feeModules模块: 运费,提进,其他,单项,采购,报关费,易港通,财务报销\n" +
            "invoiceid;抬头id\n" +
            "invoicename;抬头\n" +
            "invoicenum;税率\n" +
            "invoicestate;是否开票:开票1 不开票0  \n" +
            "currency:币种 CNY \n" +
            "exchangeRate:汇率 \n" +
            "remark:备注\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "deleted:del(0正常 1删除)\n" +
            "",httpMethod = "POST")
    public JsonResult list(PageResult2<T> page, BillFee billFee, HttpServletRequest request)  throws Exception{
        return billFeeService.list(page, billFee, getLoginUser());
    }

    /**
     * 按费用抬头导出采购费
     */
    @PreAuthorize("hasAuthority('orderB:billFee:list')")
    @PostMapping("/listByFeeName")
    @ApiOperation(value = "按费用抬头导出采购费",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "invoicename: 费用抬头\n" +
            "feeName:费用名称: 采购费\n" +
            "date1:装箱开始时间\n" +
            "date2:装箱结束时间\n" +
            " \n" +
            "返回的内容\n" +
            "packDate:装箱时间\n" +
            "billOfLading:提单号 \n" +
            "boxNum:提单号 \n" +
            "feeName:费用名称\n" +
            "invoicename: 费用抬头\n" +
            "price: 金额\n" +
            "",httpMethod = "POST")
    public JsonResult listByFeeName(PageResult2<T> page, BillFee billFee, HttpServletRequest request)  throws Exception{
        return billFeeService.listByFeeName(page, billFee, getLoginUser());
    }

    /**
     * 运费报价列表
     */
    @PreAuthorize("hasAuthority('orderB:billFee:list')")
    @PostMapping("/listAll")
    @ApiOperation(value = "订单运费列表",notes = "" +
            "billId:订单id 必填\n" +
            "type:省\n" +
            "feeName:市\n" +
            "feeState:费用状态:未确认,已确认\n" +
            "",httpMethod = "POST")
    public JsonResult listAll(BillFee billFee, HttpServletRequest request)  throws Exception{
        return billFeeService.list(billFee, getLoginUser());
    }

    /**
     * 客户
     */
    @PreAuthorize("hasAuthority('orderB:billFee:list')")
    @PostMapping("/chartTotalFee")
    @ApiOperation(value = "订单运费列表",notes = "" +
            "invoicename: 客户抬头 必填\n" +
            "返回\n\n\n" +
            "total 费用总数\n" +
            "totalList 按月费用总数 createTime,price\n" +
            "writeOff 已结清费用总数\n" +
            "writeOffList 按月已结清费用总数\n" +
            "unWriteOff 未结清费用总数\n" +
            "unWriteOffList 按月未结清费用总数\n" +
            "",httpMethod = "POST")
    public JsonResult chartTotalFee(BillFee billFee, HttpServletRequest request)  throws Exception{
        return billFeeService.chartTotalFee(billFee, getLoginUser());
    }


    /**
     * 添加订单运费
     */
    @PreAuthorize("hasAuthority('orderB:billFee:save')")
    @OperLog(value = "订单运费管理", desc = "添加", result = true)
    @PostMapping("/save")
    @ApiOperation(value = "添加订单运费",notes = "" +
            "billId:订单id 必填\n" +
            "type:类型\n" +
            "feeName:费用名称\n" +
            "standard:标准\n" +
            "fobject:费用对象 货代,司机,码头 必填\n" +
            "feeModules模块: 运费,提进,其他,单项,采购,报关费,易港通,财务报销\n" +
            "invoiceid;抬头id 必填\n" +
            "invoicenum;税率\n" +
            "invoicename;抬头 必填\n" +
            "driverName;司机姓名 必填\n" +
            "invoicestate;是否开票:开票1 不开票0  \n" +
            "currency:币种 CNY 必填\n" +
            "exchangeRate:汇率 必填\n" +
            "price:金额\n" +
            "remark:备注\n" +
            "",httpMethod = "POST")
    public JsonResult save(BillFee billFee, HttpServletRequest request) {
        return billFeeService.save(billFee, getLoginUser());
    }

    /**
     * 批量添加订单运费
     * 取消
     */
/*    @PostMapping("/saveBatch")
    @ApiOperation(value = "批量添加订单运费",notes = "" +
            "billId:订单id 必填\n" +
            "type:类型\n" +
            "feeName:费用名称\n" +
            "price:金额\n" +
            "remark:备注\n" +
            "例子:\n" +
            "[{\"billId\":145, \"type\":\"类型3\", \"feeName\":\"费用名称3\", \"price\":\"金额3\", \"remark\":\"备注3\"},{\"billId\":145, \"type\":\"类型4\", \"feeName\":\"费用名称4\", \"price\":\"金额4\", \"remark\":\"备注4\"}]\n" +
            "",httpMethod = "POST")
    */
    public JsonResult saveBatch(@RequestBody List<BillFee> billFeeList, HttpServletRequest request) {
        return billFeeService.saveBatch(billFeeList, getLoginUser());
    }


    /**
     * 订单运费修改
     */
    @PreAuthorize("hasAuthority('orderB:billFee:update')")
    @OperLog(value = "订单运费管理", desc = "修改", result = true)
    @PostMapping("/update")
    @ApiOperation(value = "订单运费修改",notes = "" +
            "id 订单运费的id 必填\n" +
            "type:类型\n" +
            "feeName:费用名称\n" +
            "standard:标准\n" +
            "price:金额\n" +
            "invoiceid;抬头id 必填\n" +
            "invoicenum;税率\n" +
            "invoicename;抬头 必填\n" +
            "driverName;抬头 必填\n" +
            "invoicestate;是否开票:开票1 不开票0  \n" +
            "currency:币种 CNY  必填\n" +
            "exchangeRate:汇率 必填\n" +
            "remark:备注\n"
            ,httpMethod = "POST")
    public JsonResult update(BillFee billFee, HttpServletRequest request) {
        return billFeeService.update(billFee, getLoginUser());
    }

    /**
     *  订单费用状态一次性都确认
     */
    @PreAuthorize("hasAuthority('orderB:billFee:update')")
    @OperLog(value = "订单费用状态一次性都确认", desc = "修改", result = true)
    @PostMapping("/updateFeeStateByBill")
    @ApiOperation(value = "订单费用状态一次性都确认",notes = "" +
            "billId 订单运费的id 必填\n" +
            "type 应收,应付,直接不传值\n" +
            "",httpMethod = "POST")
    public JsonResult updateFeeStateByBill(BillFee billFee, HttpServletRequest request) {
        return billFeeService.updateFeeStateByBill(billFee, getLoginUser());
    }

    /**
     * 订单运费费用确认
     */
    @PreAuthorize("hasAuthority('orderB:billFee:update')")
    @OperLog(value = "订单运费费用确认管理", desc = "修改", result = true)
    @PostMapping("/updateFeeState")
    @ApiOperation(value = "订单运费费用确认",notes = "" +
            "id 订单运费的id 必填\n" +
            "feeState:费用状态:未确认,已确认 必填\n"+
            "feePerson:确认人\n" +
            "feeTime:确认时间\n"
            ,httpMethod = "POST")
    // TODO: 2020/9/15  这个方法以后要删掉
    public JsonResult updateFeeState(BillFee billFee, HttpServletRequest request) {
        return billFeeService.updateFeeState(billFee, getLoginUser());
    }

    @PreAuthorize("hasAuthority('orderB:billFee:update')")
    @OperLog(value = "订单运费销账情况", desc = "修改销账情况", result = true)
    @PostMapping("/updateWriteOffAccounts")
    @ApiOperation(value = "修改订单",notes = "" +
            "id:id 必填\n" +
            "类型为应收:\n" +
            "settlementPrice;销账金额\n" +
            "settlement;//销账完成度:  0未销账 1部分 2全部 数据库里没有\n" +
            "",httpMethod = "POST")
    public JsonResult updateWriteOffAccounts(BillFeeWriteOffItem billFeeWriteOffItem, HttpServletRequest request) {
        return billFeeService.updateWriteOffAccounts(billFeeWriteOffItem, getLoginUser());
    }

    /**
     * 订单运费删除
     */
    @PreAuthorize("hasAuthority('orderB:billFee:update')")
    @OperLog(value = "订单运费管理", desc = "删除")
    @PostMapping("/remove")
    @ApiOperation(value = "订单运费删除",notes = "" +
            "id 订单运费的id 必填\n"
            ,httpMethod = "POST")
    public JsonResult remove(BillFee billFee, HttpServletRequest request) {
        return billFeeService.remove(billFee, getLoginUser());
    }
}
